<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__STATIC__/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="__STATIC__/css/public.css" media="all">
</head>

<body>
<div class="layuimini-container">
    <div class="layuimini-main">



        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-sm layui-btn-normal data-delete-btn" lay-event="grantSelect"> 发放所选人员      </button>
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="grant">发放</a>

        </script>

    </div>
</div>
<script src="__STATIC__/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: "{:url('index/MeritPayGrant/getMeritPayGrant')}",
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                { type: "checkbox", width: 50 },
                { field: 'id', width: 100, title: 'ID', sort: true },
                { field: 'wage_date', width: 150, title: '日期'},
                { field: 'name', width: 150, title: '姓名'},
                {field:'', width: 200,  title:'职位类型', templet: function (d) {
                        return salary_job_type(d.salary_job_type);
                    }
                },
                { field: 'company', width: 150, title: '所在单位' },
                { field: 'teaching_task_fee', width: 150, title: '教学任务经费' },
                { field: 'manage_fee', width: 150, title: '管理服务经费' },
                { field: 'vacancy_subsidy', width: 150, title: '缺额补贴经费' },
                { field: 'special_subsidy', width: 150, title: '特殊岗位津贴' },
                { field: 'annual_assess_fee', width: 250, title: '年度考核奖励经费' },
                { field: 'principal_award_fund', width: 250, title: '校长奖励基金' },
                { field: 'deduction_major_liability', width: 250, title: '重大责任扣除经费' },
                { field: 'mediation_funds', width: 250, title: '调节经费' },
                {field:'', width: 200,  title:'发放情况', templet: function (d) {
                        return isgrant(d.isgrant);
                    }
                },

            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line'
        });
        function salary_job_type(salary_job_type){
            //WHERE a.m_id=b.m_id AND b.m_id=c.m_id AND a.charac_no=b.charac_no AND  c.login_status=1
            if(salary_job_type == 1){
                return '<span style="color:green">在职人员</span>';
            }else if(salary_job_type == 2){
                return '<span>停发工资人员</span>';
            }else if(salary_job_type == 3){
                return '<span>退休人员</span>';
            }
        }

        function isgrant(isgrant){
            //WHERE a.m_id=b.m_id AND b.m_id=c.m_id AND a.charac_no=b.charac_no AND  c.login_status=1
            if(isgrant == 1){
                return '<span style="color:green">已发放</span>';
            }else {
                return '<span>未发放</span>';
            }
        }
        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    value: $('#value').val(),
                    modules: $('#modules').val()
                }
            }, 'data');
            return false;
        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
             if (obj.event === 'grantSelect') {  // 监听删除操作
                layer.confirm('确定发放所选人员吗？', function (index) {
                    var checkStatus = table.checkStatus('currentTableId')
                        , data = checkStatus.data;
                    var ids = [];
                    for (var i = 0; i < data.length; i++) {
                        ids.push(checkStatus.data[i].id)
                    }
                    
                    $.ajax({
                        data: { "id": ids },
                        url: "{:url('index/MeritPayGrant/grantSelect')}",
                        type: 'post',
                        success: function (data) {
                            if (data.code == 1) {
                                layer.msg(data.msg);
                            } else {
                                layer.msg(data.msg);
                            }
                        }
                    });
                    //执行搜索重载
                    table.reload('currentTableId', {
                        page: {
                            curr: 1
                        }
                    }, 'data');
                    layer.close(index);
                });
            }
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });
        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'grant') {
                var index = layer.open({
                    title: '编辑窗口',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: "{:url('index/MeritPayGrant/grant')}?id=" + data.id,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'delete') {
                layer.confirm('真的删除行么', function (index) {
                    $.post("remove", "id=" + data.user_id, function (data) {
                        if (data.code == 1) {
                            layer.msg(data.msg);
                        } else {
                            layer.msg(data.msg);
                        }
                    });
                    obj.del();
                    layer.close(index);
                });
            }
        });


    });
</script>

</body>

</html>